class Ruiqu::ProductCategoriesController < Ruiqu::BaseController
  before_action :set_store
  before_action :set_category, only: [:edit, :update, :unuse]
  def index
    @product_categories = @store.product_categories.useable
  end

  def new
    @product_category = StoreProductCategory.new()
  end

  def create
    @product_category = @store.product_categories.new(store_product_category_params)
    if @product_category.save
      redirect_to ruiqu_store_product_categories_path
    else
      render 'new', notice: @product_category.errors.full_messages.first
    end
  end

  def edit

  end

  def update
    @product_category.update(store_product_category_params)
    redirect_to ruiqu_store_product_categories_path
  end

  def unuse
    @product_category.unuse!
    redirect_to ruiqu_store_product_categories_path
  end

  private
  def set_store
    @store ||= current_store
  end

  def store_product_category_params
    params.require(:store_product_category).permit(:name)
  end

  def set_category
    @product_category = StoreProductCategory.find(params[:id])
  end
end
